﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using EntityModel;
using Services;
using Common;
namespace Heart.Controllers
{
    public class ProductAlbumController : Controller
    {
        //
        // GET: /ProductAlbum/

        #region 公用属性
        ProductService productService = new ProductService();
        ProductAlbumService productAlbumService = new ProductAlbumService();
        #endregion

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Create(int pid)
        {
            Product product = productService.GetModel(pid);
            ViewData["Name"] = product.Name;
            ViewData["PruductId"] = product.Id;
            ViewData["AlbumList"] = productAlbumService.GetAllList(pid);
            return View();
        }
        [HttpPost]
        public ActionResult Create(FormCollection c)
        {
            ProductAlbum album = new ProductAlbum();
            album.Url = WebBase.GetForm("Url");
            album.PruductId = WebBase.GetFormInt("PruductId");
            album.IsHome = true;
            album.DisplayOrder = 1;
            int pid = WebBase.GetFormInt("PruductId");
            album.PruductId = pid;
            productAlbumService.Create(album);
            return RedirectToAction("Create", new { pid = pid });
        }

        public ActionResult Delete(int pid, int id)
        {
            productAlbumService.Delete(id);
            return RedirectToAction("Create", new { pid = pid });
        }

        /// <summary>
        /// 更新相册封面
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult IsHome(int pid, int id)
        {
            productAlbumService.IsHome(pid, id);
            return RedirectToAction("Create", new { pid = pid });
        }
        

    }
}
